package br.edu.fatecou.reserva.backing.datamodel;

import java.util.ArrayList;
import java.util.List;

import javax.faces.model.ListDataModel;

import org.primefaces.model.SelectableDataModel;

import br.edu.fatecou.reserva.dominio.Local;

public class LocalDataModel extends ListDataModel<Local> implements
		SelectableDataModel<Local> {
	
	public LocalDataModel() {
		super(new ArrayList<Local>());
	}
	
	public LocalDataModel(List<Local> lista) {
		super(lista);
	}

	@SuppressWarnings("unchecked")
	@Override
	public Local getRowData(String rowKey) {
		List<Local> locais = (List<Local>) getWrappedData();
		
		Long id = Long.valueOf(rowKey);
		for (Local local : locais) {
			if (local.getCodigo().equals(id))
				return local;
		}
		
		return null;
	}

	@Override
	public Object getRowKey(Local local) {
		return local.getCodigo();
	}

}
